﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DAL;
using FCTC_Web.Models;
using FCTC_Web.Utilities;
using System.Collections;
using FCTC_Web.Controllers.Business.BusinessModel;



namespace FCTC_Web.Controllers.Business
{
    public class DefaultController : Controller
    {
        public void SetSearchEngine(string CarBrand, string BrandType, string VehicleStyle, string gears, string miles, string age, string prize)
        {
            var ns = VehicleXmlHelper.Brands;
            ViewBag.CarBrand = new SelectList(ns, CarBrand);
            if (!string.IsNullOrWhiteSpace(CarBrand))
                ViewBag.BrandType = new SelectList(VehicleXmlHelper.GetSelectiosn(CarBrand), BrandType);
            else
                ViewBag.BrandType = new SelectList(new List<string>());

            if (!string.IsNullOrWhiteSpace(BrandType))
                ViewBag.VehicleStyle = new SelectList(VehicleXmlHelper.GetvehicleType(CarBrand, BrandType), VehicleStyle);
            else
                ViewBag.VehicleStyle = new SelectList(new List<string>());

            if (!string.IsNullOrWhiteSpace(gears))
                ViewBag.gears = new SelectList(new List<string> { "手动档", "自动档", "手自一体" }, gears);
            else
                ViewBag.gears = new SelectList(new List<string> { "手动档", "自动档", "手自一体" });

            if (!string.IsNullOrWhiteSpace(miles))
                ViewBag.miles = new SelectList(
                    new List<string> { "1万公里以内", "3万公里以内", "5万公里以内", "10万公里以内", "20万公里以内" }, miles);
            else
                ViewBag.miles = new SelectList(
                    new List<string> { "1万公里以内", "3万公里以内", "5万公里以内", "10万公里以内", "20万公里以内" });

            if (!string.IsNullOrWhiteSpace(age))
                ViewBag.age = new SelectList(
                                   new List<string> { "1年以内", "3年以内", "5年以内", "10年以内", "20年以内" }, age);
            else
                ViewBag.age = new SelectList(
                                   new List<string> { "1年以内", "3年以内", "5年以内", "10年以内", "20年以内" });

            if (!string.IsNullOrWhiteSpace(prize))
                ViewBag.prize = new SelectList(
                          new List<string> { "3万以内", "5万以内", "10万以内", "20万以内", "30万以内", "50万以内" }, prize);
            else
                ViewBag.prize = new SelectList(
                    new List<string> { "3万以内", "5万以内", "10万以内", "20万以内", "30万以内", "50万以内" });
        }

        public ActionResult Index(int? pageId, string CarBrand, string BrandType, string VehicleStyle, string gears, string miles, string age, string prize)
        {
            SetSearchEngine(CarBrand, BrandType, VehicleStyle, gears, miles, age, prize);
            return View("/Views/Business/Default.cshtml", new DefaultModel());
        }


        public IEnumerable GetLatest(string brand, string style, string selection)
        {
            SetSearchEngine(brand, style, selection, null, null, null, null);
            if (CH.GetAllData<Vehicle>().Count == 0) return null;
            else return CH.GetAllData<Vehicle>().ToList();
        } 

        public ActionResult Build()
        {
            return View("/Views/Business/Build.cshtml");
        }


    }
}
